package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.AgedmallGoodsSpecificationInfoMapper;
import org.linlinjava.litemall.db.domain.AgedmallGoodsSpecificationInfo;
import org.linlinjava.litemall.db.domain.AgedmallGoodsSpecificationInfoExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class AgedmallGoodsSpecificationInfoService {
    @Resource
    private AgedmallGoodsSpecificationInfoMapper goodsSpecificationInfoMapper;

    public AgedmallGoodsSpecificationInfo getById(Integer id) {
        AgedmallGoodsSpecificationInfoExample example = new AgedmallGoodsSpecificationInfoExample();
        example.or().andDeletedEqualTo(false)
                .andIdEqualTo(id);
        return goodsSpecificationInfoMapper.selectOneByExample(example);
    }

    public List<AgedmallGoodsSpecificationInfo> getByGoodsIdAndType(Integer goodsId, String type) {
        AgedmallGoodsSpecificationInfoExample example = new AgedmallGoodsSpecificationInfoExample();
        example.or().andGoodsIdEqualTo(goodsId)
                .andTypeEqualTo(type)
                .andDeletedEqualTo(false);
        return goodsSpecificationInfoMapper.selectByExample(example);
    }

    public AgedmallGoodsSpecificationInfo getOneByGoodsIdAndType(Integer goodsId, String type) {
        List<AgedmallGoodsSpecificationInfo> list = getByGoodsIdAndType(goodsId, type);
        return list.size() > 0 ? list.get(0) : null;
    }

    //StoreGoodsVo 的id
    public List<AgedmallGoodsSpecificationInfo> getListByGoodsIds(List<Integer> goodsIdList) {
        if(goodsIdList == null || goodsIdList.size() == 0) {
            return new ArrayList<>();
        }
        AgedmallGoodsSpecificationInfoExample example = new AgedmallGoodsSpecificationInfoExample();
        example.or().andGoodsIdIn(goodsIdList)
                .andDeletedEqualTo(false);
        return goodsSpecificationInfoMapper.selectByExample(example);
    }

}
